import 'dart:math';

import 'package:animationLab/progress/custom_Linear_progress_bar.dart';
import 'package:flutter/material.dart';

class RandomProgressBar extends StatefulWidget {
  final double vlaue;
  RandomProgressBar({this.vlaue});

  @override
  _RandomProgressBarState createState() => _RandomProgressBarState();
}

class _RandomProgressBarState extends State<RandomProgressBar>
    with TickerProviderStateMixin {
  AnimationController animationController;
  double _value = 0.8;

  @override
  void initState() {
    super.initState();
    animationController = AnimationController(
      vsync: this,
      duration: Duration(milliseconds: 5000),
    );

    animationController.addListener(() {
      // _value = animationController.value;
      double value = (Random().nextDouble() + 0.5) * animationController.value;
      value = min(max(value, _value), 1);
      _value = value;
      //print(_value);
      setState(() {});
    });
    animationController.addStatusListener((status) {
      print(status);
    });
    // animationController.forward();
    //animationController.repeat(reverse: true);
  }

  @override
  Widget build(BuildContext context) {
    return CustomLinearProgressBar(
      value: _value,
      backgroundColor: Color(0xFF19191D),
      valueColor: Color(0xFF3864FF),
    );
  }
}
